import cv2

#创建窗口
cv2.namedWindow('video', cv2.WINDOW_NORMAL)
cv2.resizeWindow('video', 640, 480)

# 获取视频设备, 默认为0
cap = cv2.VideoCapture(0)

# 因为要一直读，所以用循环
while True:
    ret, frame = cap.read()

    cv2.imshow('video', frame)

    # 如果还是0， 只读取1帧
    key = cv2.waitKey(1)
    if(key & 0xFF == ord('q')):
        break

# 释放VideoCapture
cap.release()
cv2.destroyAllWindows()